package IO;

import java.io.*;
import java.util.Date;

public class ObjectStreamTest {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //对象序列化
        ObjectOutputStream outputStream = new ObjectOutputStream(
                new FileOutputStream("/Users/zhang/Documents/doc/object.obj"));
        outputStream.writeObject("hello");
        outputStream.writeObject(new Date());
        outputStream.close();
        //对象反序列化
        ObjectInputStream inputStream = new ObjectInputStream(
                new FileInputStream("/Users/zhang/Documents/doc/object.obj"));
        String str = (String) inputStream.readObject();
        Date date = (Date) inputStream.readObject();
        System.out.println(str);
        System.out.println(date.getTime());
        inputStream.close();
    }
}
